<? 
session_start();
				
include ('conn.php');
				
$db = get_conn();
				
check_session();
		  
if ($_POST['Agregar']!=""){
	$sql = "INSERT INTO locations (id_facility,number,acc_id) VALUES (".$_POST['id_facility'].",\"".htmlspecialchars($_POST['number'])."\",\"".htmlspecialchars($_POST['acc_id'])."\")";
	$result = mysql_query($sql);
 	if($result){
		$id_location = mysql_insert_id();
		//grant_access($id_location,$_POST['id_user'] )	;
 		do_redirect('../locations.php'); 	  
 	}else{
 		error_handling('locations.insert  - '.$sql,mysql_error());
 	}				  
		 
}//Agregar
		  
if ($_POST['Actualizar']!=""){
			
	$sql = "update locations set 
	id_facility=".$_POST['id_facility'].",
	number=\"".htmlspecialchars($_POST['number'])."\",
	acc_id=\"".htmlspecialchars($_POST['acc_id'])."\"
	where id_location=".$_POST['id_location'];
			 
			
	$result = mysql_query($sql);
	if($result){
		//grant_access($_POST['id_location'],$_POST['id_user'] )	;		
		do_redirect('../locations.php'); 	  
	}else{
		error_handling('locations.update - '.$sql,mysql_error());
	}				  
		 
}//update
		  
if ($_POST['Eliminar']!=""){


	
	$sql = "delete from vehicules where id_location=".$_POST['id_location'];
	$result = mysql_query($sql);
	if(!$result){
		error_handling('locations.delete - '.$sql,mysql_error());
	}	
	
	

	$sql = "delete from locations where id_location=".$_POST['id_location'];
	$result = mysql_query($sql);
	if($result){
		do_redirect('../locations.php'); 	  
	}else{
		error_handling('locations.delete - '.$sql,mysql_error());
	}				  
		 
}//delete
		  
if ($_POST['Nuevo']!=""){
				
		do_redirect('../locations.php'); 	  
		  
}//nuevo



?>
